/* 
 *  <copyright file="ActorLibrary.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using System.Collections.Generic;
using System.Xml;


using SobrietyEngine.Assets;

namespace SobrietyEngine.Actor
{
    public class ActorLibrary
    {

        Dictionary<String, ActorTemplate> templates = new Dictionary<string, ActorTemplate>();
        public Dictionary<String, ActorTemplate> Templates
        {
            get { return templates; }
            set { templates = value; }
        }
                
        IAssetGameService assetGameService;

        public ActorLibrary()
        {
        }

        public ActorLibrary(IAssetGameService ags):this()
        {
            assetGameService = ags;
        }

        public void Clear()
        {
            templates.Clear();
        }

        public void Load(String fileName)
        {
            //if we have a CM, we are likely called in gameServices
            if (assetGameService != null)
            {
                String data = assetGameService.Load<String>(fileName);
                //ActorTemplateReader.parse(ref data, templates, false, null);
                this.Templates = ActorDefinitionReader.Load(data);
            }
            else // likely being used outside of gameServices
            {
#if XBOX360
#else
                //passed in file is likely full path name
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);
                String data = xmlDoc.DocumentElement.InnerText;
                //ActorTemplateReader.parse(ref data, templates, false, null);
                this.Templates = ActorDefinitionReader.Load(data);
#endif
            }
        }        

    }
}